/******************************************************************************
 * FileName:    gwin_main_task.h
 * Desc:        main
 *
 *
 * Author:      Lin
 * Notes:
 *
 ******************************************************************************/

#ifndef __GWIN_MAIN_H__
#define __GWIN_MAIN_H__


/*-------------------------- Includes ---------------------------------------*/

/*-------------------------- Macro Definitions ------------------------------*/

/*-------------------------- Type Declarations ------------------------------*/
/**
 * @brief 消息
 */
typedef struct
{
    uint16_t type;
    uint16_t subtype;
    union
    {
        uint32_t param;
        void *buf;
        // 设置参数
        struct
        {
            uint8_t action_type;
            uint8_t reserve1;
            uint16_t reserve2;
            uint32_t cfg_value;
        };
        // 按键
        struct
        {
            uint8_t switch_index;
        };
        // 回传位置
        struct
        {
            uint8_t current_position;
        };
        // 外部动作
        struct
        {
            uint32_t ext_param;
        };
    };
}gwin_main_task_msg_t;

/**
 * @brief 消息类型
 */
typedef enum
{
    MAIN_TASK_MSG_TYPE_NONE,
    MAIN_TASK_MSG_TYPE_TASK_INIT,
    MAIN_TASK_MSG_TYPE_CFG,
    MAIN_TASK_MSG_TYPE_TIMER,
    MAIN_TASK_MSG_TYPE_BTN,
    MAIN_TASK_MSG_TYPE_MOTOR,
    MAIN_TASK_MSG_TYPE_EX_ACT,
}gwin_main_task_msg_type_t;

/**
 * @brief 设置动作类型
 */
typedef enum
{
    MAIN_TASK_MSG_CFG_ACT_TYPE_NONE,
    MAIN_TASK_MSG_CFG_ACT_TYPE_SET,
    MAIN_TASK_MSG_CFG_ACT_TYPE_GET,
    MAIN_TASK_MSG_CFG_ACT_TYPE_RESET,
    MAIN_TASK_MSG_CFG_ACT_TYPE_RESET2,
    MAIN_TASK_MSG_CFG_ACT_TYPE_DELETE,
}gwin_main_task_msg_cfg_action_type_t;

/**
 * @brief 设置消息子类型
 */
typedef enum
{
    MAIN_TASK_MSG_CFG_SUBTYPE_NONE,
    MAIN_TASK_MSG_CFG_SUBTYPE_NETWORK,
    MAIN_TASK_MSG_CFG_SUBTYPE_GATT,
    MAIN_TASK_MSG_CFG_SUBTYPE_OTA_STATE,
    MAIN_TASK_MSG_CFG_SUBTYPE_CURTAIN_STATE,
    MAIN_TASK_MSG_CFG_SUBTYPE_CURRENT_POSITION,
    MAIN_TASK_MSG_CFG_SUBTYPE_TARGET_POSITION,
    MAIN_TASK_MSG_CFG_SUBTYPE_DIRECTION,
    MAIN_TASK_MSG_CFG_SUBTYPE_SPEED_LEVEL,
    MAIN_TASK_MSG_CFG_SUBTYPE_STROKE_MIN,
    MAIN_TASK_MSG_CFG_SUBTYPE_STROKE_MAX,
    MAIN_TASK_MSG_CFG_SUBTYPE_NODE_MODE,
    MAIN_TASK_MSG_CFG_SUBTYPE_PRODUCT_CFG,
}gwin_main_task_msg_cfg_subtype_t;

/**
 * @brief 定时器消息子类型
 */
typedef enum
{
    MAIN_TASK_MSG_TIMER_SUBTYPE_NONE,
    MAIN_TASK_MSG_TIMER_SUBTYPE_ONE_SECOND,
}gwin_main_task_msg_timer_subtype_t;

/**
 * @brief 按键消息子类型
 */
typedef enum
{
    MAIN_TASK_MSG_BTN_SUBTYPE_NONE,
    MAIN_TASK_MSG_BTN_SUBTYPE_PRESS_DOWN,
    MAIN_TASK_MSG_BTN_SUBTYPE_PRESS_UP,
    MAIN_TASK_MSG_BTN_SUBTYPE_CLICK_REPEAT,
    MAIN_TASK_MSG_BTN_SUBTYPE_SINGLE_CLICK,
    MAIN_TASK_MSG_BTN_SUBTYPE_DOUBLE_CLICK,
    MAIN_TASK_MSG_BTN_SUBTYPE_LONG_PRESS_DOWN,
    MAIN_TASK_MSG_BTN_SUBTYPE_LONG_PRESS_UP,
    MAIN_TASK_MSG_BTN_SUBTYPE_LONG_PRESS_HOLD,
    MAIN_TASK_MSG_BTN_SUBTYPE_MAX,
}gwin_main_task_msg_btn_subtype_t;

/**
 * @brief 电机消息子类型
 */
typedef enum
{
    MAIN_TASK_MSG_MOTOR_SUBTYPE_NONE,
    MAIN_TASK_MSG_MOTOR_SUBTYPE_UPDATE,
    MAIN_TASK_MSG_MOTOR_SUBTYPE_IDLE,
}gwin_main_task_msg_motor_subtype_t;

/**
 * @brief 外部动作消息子类型
 */
typedef enum
{
    MAIN_TASK_MSG_EX_ACT_SUBTYPE_NONE,
    MAIN_TASK_MSG_EX_ACT_SUBTYPE_CURTAIN_TOGGLE,
    MAIN_TASK_MSG_EX_ACT_SUBTYPE_CALIBRATION,
    MAIN_TASK_MSG_EX_ACT_SUBTYPE_REMOTE_PAIR_START,
    MAIN_TASK_MSG_EX_ACT_SUBTYPE_REMOTE_PAIR_CLEAR,
    MAIN_TASK_MSG_EX_ACT_SUBTYPE_NET_RESET,
    MAIN_TASK_MSG_EX_ACT_SUBTYPE_FACTORY_TEST,
    MAIN_TASK_MSG_EX_ACT_SUBTYPE_FACTORY_RESET,
    MAIN_TASK_MSG_EX_ACT_SUBTYPE_RESET_ALL_FORCE,       // 强制复位所有参数（研发预留接口，防止错误，直接响应）
}gwin_main_task_msg_ex_act_subtype_t;


/*-------------------------- Global Variables -------------------------------*/

/*-------------------------- Local Variables --------------------------------*/

/*-------------------------- Functions Declarations -------------------------*/

/*-------------------------- Functions Definitions --------------------------*/
void gwin_main_task_init(void);
#define gwin_send_msg_to_main_task(p_msg)           os_msg_send(gwin_main_task, p_msg)

void gwin_main_btn_event(uint8_t switch_index, uint8_t btn_event);
void gwin_main_motor_update(uint8_t current_position);
void gwin_main_motor_idle(uint8_t current_position);
void gwin_main_extern_action(uint8_t action);
void gwin_main_extern_action_with_param(uint8_t action, uint32_t param);

void gwin_main_cfg_set(uint32_t cfg_index, uint32_t value);
void gwin_main_cfg_get(uint32_t cfg_index, uint32_t value_addr);
void gwin_main_cfg_reset(uint32_t cfg_index, uint32_t value);
void gwin_main_cfg_reset2(uint32_t cfg_index, uint32_t value);
void gwin_main_cfg_delete(uint32_t cfg_index, uint32_t value);

void gwin_main_network_reset(uint8_t network_restore_manual);


#endif // __GWIN_MAIN_H__


/*-------------------------- END OF FILE ------------------------------------*/

